#!/bin/bash

data_path=/app/dmpdata
start_date=$1
username=zxcms_e
password=zxcms

if [ -z "${start_date}" ]; then
  echo "Example: impdata.sh 20210827"
  exit
fi

echo "Starting imp `date -d ${start_date} +%Y%m%d` data"
  
if [ ! -d "$data_path/zhengxin$start_date" ]; then
  mkdir -p "$data_path/zhengxin$start_date"
  tar -xf $data_path/zhengxin$start_date.tar -C $data_path/zhengxin$start_date
fi
    
if [ ! -f "$data_path/zhengxin$start_date/zhengxin_cbs.dmp" ]; then
  gzip -d $data_path/zhengxin$start_date/zhengxin_cbs.dmp.gz
fi

if [ ! -f "$data_path/zhengxin$start_date/zhengxin_cms.dmp" ]; then
  gzip -d $data_path/zhengxin$start_date/zhengxin_cms.dmp.gz
fi

if [ ! -f "$data_path/zhengxin$start_date/cbs_ln_mst_hst.dmp" ]; then
  gzip -d $data_path/zhengxin$start_date/cbs_ln_mst_hst.dmp.gz
fi

sqlplus -S ${username}/${password}@10.18.37.35:1521/hnzx<<EOF
@${/app/dmpdata}/truncatetable.sql;
exit;
EOF

imp ${username}/${password}@10.18.37.35:1521/hnzx \
  file=${data_path}/zhengxin${start_date}/zhengxin_cbs.dmp \
  tables=CBS_DD_MST,CBS_LN_MST,CBS_LN_PAY_PLN,CBS_LN_REG \
  data_only=y \
  ignore=y \
  log=$data_path/logs/zhengxin_cbs.log
  
  
imp ${username}/${password}@10.18.37.35:1521/hnzx \
  file=${data_path}/zhengxin${start_date}/zhengxin_cms.dmp \
  tables=CMS_CIF_CORP_INF,CMS_CIF_FIN_CAP_DATA,CMS_CIF_PERS_INF,CMS_GAGE_REG,CMS_LN_DUE,CMS_LN_PACT,CMS_RISK_FIVE \
  data_only=y \  
  ignore=y \
  data_only=y \
  log=$data_path/logs/zhengxin_cms.log
  
  
imp ${username}/${password}@10.18.37.35:1521/hnzx \
  file=${data_path}/zhengxin${start_date}/cbs_ln_mst_hst.dmp \
  tables=cbs_ln_mst_hst \
  data_only=y \
  ignore=y \
  log=$data_path/logs/cbs_ln_mst_hst.log

echo "finished imp data"

